package main.leetcode.offer.secondround.from51to68;

import main.datastruc.TreeNode;

/** 54.二叉搜索树中第k大的数 */
public class ex54 {
    private int cnt;
    private int res;

    public int kthLargest(TreeNode root, int k) {
        if (root != null) {
            kthLargest(root.right, k);
            if (++cnt == k) {
                return (res = root.val);
            }
            kthLargest(root.left, k);
        }
        return res;
    }
}
